import java.util.HashMap;
import java.util.HashSet;

public class Test {

    public int singleNumber(int[] nums) {
        HashSet<Integer> hashSet = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (!hashSet.contains(nums[i])) {
                hashSet.add(nums[i]);
            }else {
                hashSet.remove(nums[i]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if(hashSet.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }
}

//public void hah(){}